﻿using System.Collections.Generic;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle;
using LBoL.Core.Cards;
using LBoL.Core;
using ProbeMod.Cards.Template;
using LBoLEntitySideloader.Attributes;

namespace ProbeMod.Cards
{
    public sealed class ProbeObserverDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();

            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Skill;
            config.Rarity = Rarity.Common;

            config.Colors = new List<ManaColor>() { ManaColor.Blue };
            config.Cost = new ManaGroup() { Any=1  };
            config.UpgradedCost = ManaGroup.Empty;
            config.AutoPerform = true;

            config.Scry = 3;
            config.UpgradedScry = 3;

            config.Value1 = 1;  // 保留时占卜

            config.Keywords = Keyword.Retain;
            config.UpgradedKeywords = Keyword.Retain;

            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }

        /// <summary>
        /// ob
        /// 1/0 保留 占卜3。在手中:回合开始时，占卜1,抽1
        /// </summary>
        [EntityLogic(typeof(ProbeObserverDef))]
        public sealed class ProbeObserver : ProbeCard
        {
            protected override void OnEnterBattle(BattleController battle)
            {
                ReactBattleEvent(base.Battle.Player.TurnStarting, OnPlayerTurnStarting);
            }

            private IEnumerable<BattleAction> OnPlayerTurnStarting(UnitEventArgs args)
            {
                if (!base.Battle.BattleShouldEnd && base.Zone == CardZone.Hand)
                {
                    yield return new ScryAction(new ScryInfo() { Count = Value1 });
                }
            }

            protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
            {
                yield return new ScryAction(Scry);
                yield return new DrawCardAction();
            }
        }
    }
}
